package JUnit;

import static org.junit.Assert.assertTrue;

import org.junit.Before;
import org.junit.Test;

import protocol.Headers;
import Servlets.WhatsAppConstatnts;

public class Login extends mainTest {

	@Before
	public void setUp() throws Exception {
		_url = "login";
	}

	@Test
	public void testLogin() {
		String response1 = this
				.runtest(new RunnableClient(
						"localhost",
						9969,
						"POST /"
								+ _url
								+ ".jsp HTTP/1.1\n\nUserName=yochailehman2&Phone=0546861622\n$"));
		assertTrue(response1.contains("Set-Cookie: SESSIONID="));
		assertTrue(response1.contains("yochailehman2@0546861622"));
	}

	@Test
	public void test403() {
		String response1 = this
				.runtest(new RunnableClient(
						"localhost",
						9969,
						"POST /"
								+ _url
								+ ".jsp HTTP/1.1\n\nUserkName=yochailehman2&Phone=0546861622\n$"));
		assertTrue(!response1.contains("HTTP/1.1 " + Headers.STATUS_403));
	}

	@Test
	public void test913WrongUserName() {
		String response3 = this
				.runtest(new RunnableClient(
						"localhost",
						9969,
						"POST /"
								+ _url
								+ ".jsp HTTP/1.1\n\nUserName=yochailehman2&Phone=0546861622\n$"));
		String response1 = this
				.runtest(new RunnableClient(
						"localhost",
						9969,
						"POST /"
								+ _url
								+ ".jsp HTTP/1.1\n\nUserName=yochailehman22&Phone=0546861622\n$"));
		assertTrue(response1.contains(WhatsAppConstatnts.ERROR_913));
	}

	@Test
	public void test913WrongPhone() {
		String response3 = this
				.runtest(new RunnableClient(
						"localhost",
						9969,
						"POST /"
								+ _url
								+ ".jsp HTTP/1.1\n\nUserName=yochailehman2&Phone=0546861622\n$"));
		String response1 = this
				.runtest(new RunnableClient(
						"localhost",
						9969,
						"POST /"
								+ _url
								+ ".jsp HTTP/1.1\n\nUserName=yochailehman2&Phone=0546861623\n$"));
		assertTrue(response1.contains(WhatsAppConstatnts.ERROR_913));
	}

	@Test
	public void test405() {
		String response1 = this
				.runtest(new RunnableClient(
						"localhost",
						9969,
						"GET /"
								+ _url
								+ ".jsp HTTP/1.1\n\nUserName=yochailehman2&Phone=0546861622\n$"));
		assertTrue(response1.contains("HTTP/1.1 " + Headers.STATUS_405));
	}
}
